<template>
	<view class="help_sell w100">
		<view class="tab_nav">
			<nav-bar nav_btn="back" :type="type" :title="title" :color="color" :auto_img="image"></nav-bar>
		</view>
		<view class="head_back_box">
			<image class="w100 h100" src="../static/bang_back.png" mode=""></image>
		</view>
		<view class="top_kuang w100">
			<image class="w100 h100" src="../static/top_kuang.png" mode=""></image>
		</view>
		<view class="form_list_box">
			<view class="list_box flex">
				<view class="left_txt s28 family f500">邀请码</view>
				<input :disabled="uid != 0" class="right_txt s28 family f500" type="text" v-model="yqm" placeholder="邀请码" />
			</view>
			<view class="list_box flex">
				<view class="left_txt s28 family f500">所在地</view>
				<view class="left_txt s28 family f500" style="width: 500upx; overflow: hidden; text-overflow: ellipsis; white-space: nowrap" @click="btnClick">
					{{ addressData.formatted_address == '' ? '选择地址' : addressData.formatted_address }}
				</view>
			</view>
			<view class="list_box flex">
				<view class="left_txt s28 family f500">姓名</view>
				<input class="uni_ipt s28 family f500" type="text" v-model="name" placeholder="请输入姓名" />
			</view>
			<view class="list_box flex">
				<view class="left_txt s28 family f500">证件名称</view>
				<uni-data-picker :localdata="items" placeholder="选择证件" popup-title="选择证件" @change="onchangeTwo" @nodeclick="onnodeclick"></uni-data-picker>
			</view>
			<view class="list_box flex">
				<view class="left_txt s28 family f500">证件号码</view>
				<input class="uni_ipt s28 family f500" type="text" v-model="zjhm" placeholder="输入证件号码" />
			</view>
			<view class="list_box flex">
				<view class="left_txt s28 family f500">性别</view>
				<uni-data-picker :localdata="xinBieList" placeholder="选择性别" popup-title="选择性别" @change="onchangeThree"></uni-data-picker>
			</view>
			<!-- <view class="list_box flex">
				<view class="left_txt s28 family f500">
					出生日期
				</view>
				<uni-datetime-picker type="date" :value="single" start="2021-3-20" end="2111-6-30" @change="change" />
			</view> -->
			<view class="submit_btn s32 fblod familytow txtali" @click="goHelpSubmit">提交</view>
		</view>
		<view class="baijing" v-if="show1">
			<view class="bj_box">
				<view class="bj_head_img">
					<image class="w100 h100" src="../static/sqxz.png" mode=""></image>
				</view>
				<view class="bj_bon_box">
					<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y">
						<view id="demo1" class="scroll-view-item uni-bg-red f500 s26 family">
							<rich-text :nodes="instructions"></rich-text>
						</view>
					</scroll-view>
				</view>
				<view class="flex">
					<view class="left_btn s32 familytow fblod txtali" @click="noProcess">不同意</view>
					<view class="right_btn s32 familytow fblod txtali" @click="goProcess">同意</view>
				</view>
			</view>
		</view>
		<wanl-address ref="wanlAddress" @selectAddress="successSelectAddress"></wanl-address>
	</view>
</template>

<script>
import wanlAddress from '@/components/wanl-address.vue';
export default {
	components: {
		wanlAddress
	},
	data() {
		return {
			show1: true,
			title: '',
			image: '../static/left_jian.png',
			color: 'white',
			single: '2021-04-3',
			items: [],
			xinBieList: [
				{
					text: '保密',
					value: 0
				},
				{
					text: '男',
					value: 1
				},
				{
					text: '女',
					value: 2
				}
			],
			suizaidi: '',
			yqm: '',
			name: '',
			zjhm: '',
			sfz: null,
			grend: null,
			addressData: {
				name: '',
				mobile: '',
				default: 0,
				//地区
				country: '', // 国家
				province: '', //省份
				city: '', // 城市
				citycode: '', // 城市代码
				district: '', // 县
				adcode: '', // 地区代码
				formatted_address: '', //详细地区
				//详情
				address: '', //详细地址
				address_name: '', // 地址名称
				location: '' //经纬度
			},
			uid: 0,
			instructions: '',
			isShare: false,
			type: ''
		};
	},
	onLoad(e) {
		if (e.scene || e.uid) {
			this.type = 2;
			this.isShare = true;
			if (e.scene) {
				this.yqm = e.scene.split('%3D')[1];
			}
			if (e.uid) {
				this.uid = e.uid;
				this.yqm = e.yqm;
			}
		} else {
			this.getcardType();
			this.getSubmit();
			this.getInstructions();
		}
	},
	onShow() {
		if (this.isShare) {
			this.$getLocation()
				.then((res) => {
					if (uni.getStorageSync('userInfo')) {
						this.getcardType();
						this.getSubmit();
						this.getInstructions();
						// 判断申请状态
						let that = this;
						that
							.$request({
								url: 'member/getInfo',
								method: 'POST'
							})
							.then((res) => {
								if (res.statusCode == 200) {
									let memberData = res.data.data;
									let isMayhehuoren;
									if (res.data.data.shop != null && res.data.data.shop.length != 0 && res.data.data.shop) {
										isMayhehuoren = false;
									} else {
										isMayhehuoren = true;
									}
									this.$request({
										url: 'partners/question_sure_info',
										method: 'POST',
										data: {
											user_id: uni.getStorageSync('userInfo').id
										}
									}).then((res) => {
										if (res.data.code == 1) {
											let sure = res.data.data.question.sure;
											// 点击帮买分成
											if (!isMayhehuoren) {
												this.goProcess();
												uni.showToast({
													title: '您是会员身份为商家职员，不能申请平台城市合伙人资格',
													icon: 'none'
												});
												return;
											}
											if (sure == 1 && memberData.identity != 4) {
												this.goProcess();
												uni.showToast({
													title: '您已完成城市合伙人申请，请耐心等待工作人员审核。',
													icon: 'none'
												});
												return;
											}
											if (memberData.identity == 4) {
												this.goProcess();
												uni.showToast({
													title: '您已是城市合伙人身份，请勿重复申请',
													icon: 'none'
												});
												return;
											}
											let status = res.data.data.status;
											if (status == 1) {
												uni.navigateTo({
													url: './helpSubmit'
												});
											}
											if (status == 2 || status == 3) {
												uni.navigateTo({
													url: '/pages/answer/answer?finshow=' + true
												});
											}
										}
									});
								}
							});
					} else {
						uni.navigateTo({
							url: '/pages/user/login'
						});
					}
				})
				.catch((err) => {
					this.$wanlshop.msg('您拒绝了授权');
					if (uni.getStorageSync('userInfo')) {
						this.getcardType();
						this.getSubmit();
						this.getInstructions();
					} else {
						uni.navigateTo({
							url: '/pages/user/login'
						});
					}
				});
		}
	},
	methods: {
		// 获取申请须知
		getInstructions() {
			this.$request({
				url: 'common/config',
				method: 'POST',
				data: {
					keyword: 'partner'
				}
			}).then((res) => {
				if (res.statusCode == 200) {
					this.instructions = res.data.data;
				}
			});
		},
		// 获取地址信息
		successSelectAddress(address) {
			console.log(3333, address);
			this.addressData.country = address.country;
			this.addressData.province = address.province;
			this.addressData.city = address.city;
			this.addressData.citycode = address.citycode;
			this.addressData.district = address.district;
			this.addressData.formatted_address = address.formatted_address;
			this.addressData.location = address.location;
			this.addressData.adcode = address.adcode;
			// this.addressList.location = address.location;
			// this.addressList.adcode = address.adcode;
		},
		// 显示选择地址弹窗
		btnClick() {
			this.$refs.wanlAddress.show();
		},
		// 默认请求提交
		getSubmit() {
			this.$request({
				url: 'partner/apply_partner'
			}).then((res) => {
				return false;
			});
		},
		// 获取证件类型
		getcardType() {
			this.$request({
				url: 'common/cardType'
			}).then((res) => {
				if (res.statusCode == 200) {
					this.items = res.data.data.list.map((item, index) => {
						return {
							text: item.name,
							value: index
						};
					});
				}
			});
		},
		change(e) {
			this.single = e;
		},
		// 提交表单
		goHelpSubmit() {
			if (this.name != '' && this.yqm != '' && this.zjhm != '' && this.sfz != null && this.grend != null) {
				this.$request({
					url: 'partner/apply_partner',
					method: 'POST',
					data: {
						invite_code: this.yqm,
						name: this.name,
						id_card: this.zjhm,
						card_type: this.sfz,
						sex: this.grend,
						birth: this.single,
						address: this.addressData.formatted_address,
						re_uidL: this.uid
					}
				}).then((res) => {
					if (res.data.code == 1) {
						uni.showToast({
							title: '填写完成',
							icon: 'none'
						});
						setTimeout(() => {
							uni.navigateTo({
								url: './helpSubmit'
							});
						}, 800);
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						});
					}
				});
			} else {
				uni.showToast({
					title: '请完善信息',
					icon: 'none',
					duration: 2000
				});
			}
		},
		onchangeOne(e) {
			const value = e.detail.value;
			this.suizaidi = value[0].text + value[1].text + value[2].text;
		},
		onchangeTwo(e) {
			this.sfz = e.detail.value[0].value;
		},
		onchangeThree(e) {
			this.grend = e.detail.value[0].value;
		},
		onnodeclick(node) {
			return false;
		},
		noProcess() {
			uni.navigateBack({});
		},
		goProcess() {
			this.show1 = !this.show1;
		}
	}
};
</script>

<style scoped lang="scss">
.help_sell {
	padding-bottom: 100upx;
	overflow: hidden;
	background: linear-gradient(180deg, #e8a758 0%, #ebbe87 100%);

	.head_back_box {
		width: 681upx;
		height: 464upx;
		margin: 82upx auto;
	}

	.top_kuang {
		height: 86upx;
	}

	.form_list_box {
		width: 686upx;
		background: #ffffff;
		border-radius: 24upx 24upx 24upx 24upx;
		margin: -48upx auto;
		padding-bottom: 50upx;

		.list_box {
			width: 622upx;
			height: 150upx;
			border-bottom: 2upx solid #f4f4f4;
			margin: 0 auto;

			.left_txt {
				width: 112upx;
				line-height: 150upx;
				color: #333333;
				margin-right: 20upx;
			}

			.uni_ipt {
				margin-top: 50upx;
			}

			/deep/ .uni-data-tree {
				margin-top: 34upx;
			}

			/deep/ .input-value-border {
				border: none !important;
			}

			/deep/ .input-value {
				padding: 0;
			}

			/deep/ .selected-list {
				padding: 0;
			}

			/deep/ .uni-date-x--border {
				border: none !important;
			}

			/deep/ .uni-date-x {
				padding: 0;
				margin-top: 32upx;
			}

			.right_txt {
				margin-top: 52upx;
				color: #844902;
			}
		}

		.submit_btn {
			width: 622upx;
			height: 100upx;
			background: #c06f0c;
			border-radius: 50upx 50upx 50upx 50upx;
			line-height: 100upx;
			color: #ffffff;
			margin: 40upx auto;
		}
	}

	.tab_nav {
		position: absolute;
		z-index: 999;
	}

	.baijing {
		width: 100%;
		height: 1624upx;
		background-color: rgba(0, 0, 0, 0.5);
		position: fixed;
		top: 0;
		z-index: 999;

		.bj_box {
			width: 552upx;
			background: #ffffff;
			border-radius: 32upx 32upx 32upx 32upx;
			margin: 60% auto;

			.bj_head_img {
				width: 552upx;
				height: 168upx;
			}
		}

		.bj_bon_box {
			width: 486upx;
			height: 426upx;
			margin: 26upx auto;

			.scroll-Y {
				height: 426upx;

				.scroll-view-item {
					color: #333333;
				}
			}
		}

		.left_btn {
			width: 276upx;
			height: 100upx;
			background: #cccccc;
			border-radius: 0upx 0upx 0upx 32upx;
			color: #ffffff;
			line-height: 100upx;
		}

		.right_btn {
			width: 276upx;
			height: 100upx;
			background: #ebbe87;
			border-radius: 0upx 0upx 32upx 0upx;
			line-height: 100upx;
			color: #844902;
		}
	}
}
</style>